<?php


namespace App\Admin\Actions\Post;


use App\Admin\Actions\RowAction;
use App\Models\AdminUser;
use App\Transverse;
use Encore\Admin\Actions\Response;
use Illuminate\Http\Request;

class TransverseFileImport extends RowAction
{
    public $name = '附件';

    public function handle(Transverse $model, Request $request): Response
    {
        $file = $request->file('file');
        if ($file) {
            $model->storeFile($file, 'file');
        }
        return $this->response()->success('操作成功')->refresh();
    }

    public function form()
    {
        $this->file('file', '请选择合同文件')->required();
    }

    public function authorize(AdminUser $user, $model): bool
    {
        return $user->role_type == 1 || ($model['review_status'] != 1 && $model['user_id'] == $user['id']);
    }
}
